// TreeSync.cpp : Defines the entry point for the console application.

#include <string>
#include <vector>
#include <stack>
#include <iostream>
#include <windows.h>
#include <time.h>
#include <memory>
#include <algorithm>
#include <iterator>
#include <unordered_map>

using namespace std;

enum item_type
{
    FILE_TYPE,   
    FOLDER_TYPE
};

typedef long sync_node_id;

class sync_info
{
public:
    sync_info(){}
    sync_info(const long long init_version) 
        : version(init_version)
    {
    }
    long long get_version() const
    {
        return version;
    }
private:
    long long version;
};

struct sync_node
{
public:
    sync_node(){}
    sync_node(wchar_t* name):name(name){}
    item_type local_type;
    item_type remote_type;
    sync_info local_info;
    sync_info remote_info;
    pair<sync_info, sync_info> synced_pair;
    wstring name;
    vector<sync_node_id> children;
    sync_node_id parent_id;
    sync_node_id id;
public:
    bool operator <(const sync_node& rhs)
    {
        return this->name < rhs.name;
    }
};


class sync_tree
{
public:

private:
    vector<sync_node> all_nodes;
};


auto sync_nodeComparator = [](sync_node* lhs, sync_node* rhs){return *lhs < *rhs;};

void Mergesync_node(sync_node* local, sync_node* remote)
{
}

bool recursive_fs_scan(const wstring& path, const wstring& mask, unordered_map<long long, sync_node>& files) 
{
    HANDLE hFind = INVALID_HANDLE_VALUE;
    WIN32_FIND_DATA ffd;
    wstring spec;
    spec = path + L"\\" + mask;
    hFind = FindFirstFile(spec.c_str(), &ffd);
    if (hFind == INVALID_HANDLE_VALUE)
    {
       return false;
    } 

    do
    {
        if (wcscmp(ffd.cFileName, L".") != 0 && 
            wcscmp(ffd.cFileName, L"..") != 0)
        {
            if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            {
                long long lastUpdteTime = (ffd.ftLastWriteTime.dwHighDateTime);
                lastUpdteTime = (lastUpdteTime << 32) + ffd.ftLastWriteTime.dwLowDateTime;
                recursive_fs_scan(path + L"\\" + ffd.cFileName, mask, files);
            }
            files.insert(make_pair(rand() * rand(), sync_node(ffd.cFileName)));

        }
    } while (FindNextFile(hFind, &ffd) != 0);

    FindClose(hFind);
    hFind = INVALID_HANDLE_VALUE;
    return true;
}
int main(int argc, char* argv[])
{
    unordered_map<long long, sync_node> files;
    clock_t start = clock();
    sync_node *root = new sync_node();
    // ScanLocal(L"E:\\", L"*", files, root);
    recursive_fs_scan(L"E:\\", L"*", files);
    cout << "files : " << files.size() << endl;
    cout << clock() - start << endl;
    
    
    cout << "sizeof(sync_node)" << sizeof(sync_node) << endl;
    int x;
    cin >> x;

    return 0;
}


